#include "tim.h"
#include "arguments.h"
void timer_config(void)
{
    /* -----------------------------------------------------------------------
    TIMER2CLK is 100KHz
    TIMER2 channel0 duty cycle = (25000/ 50000)* 100  = 50%
    ----------------------------------------------------------------------- */
    timer_parameter_struct timer_initpara;
	rcu_timer_clock_prescaler_config(RCU_TIMER_PSC_MUL4);
//	
    rcu_periph_clock_enable(RCU_TIMER2);
    timer_deinit(TIMER2);
    /* TIMER configuration */
    timer_initpara.prescaler         = 2400-1;
    timer_initpara.alignedmode       = TIMER_COUNTER_EDGE;
    timer_initpara.counterdirection  = TIMER_COUNTER_UP;
    timer_initpara.period            = TIM2_Trigger_Cycle*500 - 1;
    timer_initpara.clockdivision     = TIMER_CKDIV_DIV1;
    timer_initpara.repetitioncounter = 0;
    timer_init(TIMER2,&timer_initpara);
    /* auto-reload preload enable */
    timer_auto_reload_shadow_enable(TIMER2);
	timer_interrupt_enable(TIMER2,TIMER_INT_UP);
	nvic_irq_enable(TIMER2_IRQn, 0, 1);
    /* auto-reload preload enable */
    timer_enable(TIMER2);
//	
	rcu_periph_clock_enable(RCU_TIMER3);
    timer_deinit(TIMER3);
    /* TIMER configuration */
    timer_initpara.prescaler         = 240-1;
    timer_initpara.alignedmode       = TIMER_COUNTER_EDGE;
    timer_initpara.counterdirection  = TIMER_COUNTER_UP;
    timer_initpara.period            = TIM3_Trigger_Cycle*500 - 1;
    timer_initpara.clockdivision     = TIMER_CKDIV_DIV1;
    timer_initpara.repetitioncounter = 0;
    timer_init(TIMER3,&timer_initpara);
    /* auto-reload preload enable */
    timer_auto_reload_shadow_enable(TIMER3);
	timer_interrupt_enable(TIMER3,TIMER_INT_UP);
	nvic_irq_enable(TIMER3_IRQn, 0, 2);
    /* auto-reload preload enable */
    timer_enable(TIMER3);
	
	rcu_periph_clock_enable(RCU_TIMER4);
    timer_deinit(TIMER4);
    /* TIMER configuration */
    timer_initpara.prescaler         = 240-1;
    timer_initpara.alignedmode       = TIMER_COUNTER_EDGE;
    timer_initpara.counterdirection  = TIMER_COUNTER_UP;
    timer_initpara.period            = TIM4_Trigger_Cycle*500 - 1;
    timer_initpara.clockdivision     = TIMER_CKDIV_DIV1;
    timer_initpara.repetitioncounter = 0;
    timer_init(TIMER4,&timer_initpara);
    /* auto-reload preload enable */
    timer_auto_reload_shadow_enable(TIMER4);
	timer_interrupt_enable(TIMER4,TIMER_INT_UP);
	nvic_irq_enable(TIMER4_IRQn, 0, 3);
    /* auto-reload preload enable */
    timer_enable(TIMER4);
}
